#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "addcollegewindow.h"
#include "addeventwindow.h"
#include "addresultwindow.h"
#include "displayresultswindow.h"
#include "displaydatawindow.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void addCollege(const QString& name);
    void addEvent(const QString& name, int isTopFive, bool isMale);
    void addResult(int collegeId, int eventId, int rank);
    void displayResults();
    void displayCollegesAndEvents();
    void displayResultsByEvent();
    void saveData();
    void loadData();
    void modifyCollege(int id, const QString& newName);
    void modifyEvent(int id, const QString& newName, int isTopFive);
    void deleteResult(int collegeId, int eventId);

private slots:
    void on_addCollegeButton_clicked();
    void on_addEventButton_clicked();
    void on_addResultButton_clicked();
    void on_displayResultsButton_clicked();
    void on_displayDataButton_clicked();
    void on_displayResultsByEventButton_clicked(); // 添加此行
    void on_modifyCollegeButton_clicked();
    void on_modifyEventButton_clicked();
    void on_deleteResultButton_clicked();
    void handleCollegeAdded(const QString &name);
    void handleEventAdded(const QString &name, int isTopFive, bool isMale);
    void handleResultAdded(int collegeId, int eventId, int rank);

private:
    Ui::MainWindow *ui;
    AddCollegeWindow *addCollegeWindow;
    AddEventWindow *addEventWindow;
    AddResultWindow *addResultWindow;
    DisplayResultsWindow *displayResultsWindow;
    DisplayDataWindow *displayDataWindow;

    struct College {
        int id;
        QString name;
        int points;
        College* next;
    };

    struct Event {
        int id;
        QString name;
        int isTopFive;
        int isMale;
        Event* next;
    };

    struct Result {
        int collegeId;
        int eventId;
        int rank;
        Result* next;
    };

    College* collegeHead = nullptr;
    Event* eventHead = nullptr;
    Result* resultHead = nullptr;
    int collegeCount = 0;
    int eventCount = 0;
};

#endif // MAINWINDOW_H

